package com.example.hellodemo.animation;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.widget.TextView;

import com.example.hellodemo.R;

public class ObjectAnimationActivity extends AppCompatActivity {
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_object_animation);
        textView = findViewById(R.id.animation_tx);

       //  translationX() 动画到哪 ， translationXBy() 动画执行多少
        textView.animate().translationXBy(100).setDuration(3000).start();
        textView.animate().alpha(0).setDuration(3000).start();


        ValueAnimator valueAnimator = ValueAnimator.ofInt(0,100);
        valueAnimator.setDuration(2000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // valueAnimator实际值
                Log.d("valueAnimator",animation.getAnimatedValue() + "");
                // 动画的进度 0-1
                Log.d("valueAnimator",animation.getAnimatedFraction() + "");

                textView.setX(new Float(animation.getAnimatedValue().toString()));
            }
        });
        valueAnimator.start();


        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView,"translationY",0,500,200,800);
        objectAnimator.setDuration(2000);
        objectAnimator.start();

    }
}
